# my_class
class Class:

    # 类的属性
    attribute = 12312

    # 类的方法
    def function(self):
        return 'hello world'


# 实例化
c = Class()
# 访问类的属性和方法
print("myclass类的属性i为：", c.attribute)
print("myclass类的方法f输出为：", c.function())


class Complex:

    # 构造方法
    def __init__(self, real_part, imag_part):
        self.r = real_part
        self.i = imag_part


x = Complex(3.0, -4.5)
print("构造方法", x.r, x.i)


# self 代表类的实例，而非类
class Test:

    def prt(self):
        print(self)
        print(self.__class__)


t = Test()
t.prt()


# 类的方法
class People:
    name = ""
    age = 0

    # 定义的私有变量， 在类的外部是无法访问的
    __weight = 0
    
    def __init__(self, n, a, w):
        self.name = n
        self.age = a
        self.__weight = w
        
    def speak(self):
        print("%s 说: 我 %d 岁。" % (self.name, self.age))


p = People("runoob", 10, 30)
p.speak()


# 类的继承
class Student(People):
    grade = ''

    # 构造函数
    def __init__(self, n, a, w, g):

        # 调用父类的构造函数
        People.__init__(self, n, a, w)
        self.grade = g

    def speak(self):
        print("%s 说: 我 %d 岁了，我在读 %d 年级" % (self.name, self.age, self.grade))


s = Student('ken', 10, 60, 3)
s.speak()


#
class Speaker:
    topic = ''
    name = ''

    def __init__(self, n, t):
        self.name = n
        self.topic = t

    def speak(self):
        print("我叫 %s，我是一个演说家，我演讲的主题是 %s" % (self.name, self.topic))


# 多继承
class Sample(Speaker, Student):

    a = ''

    def __init__(self, n, a, w, g, t):
        Student.__init__(self, n, a, w, g)
        Speaker.__init__(self, n, t)


test = Sample("tim", 25, 80, 1, "python")
test.speak()
